package com.activity.bean;

import com.example.apple.ddhr_new.utils.StringUtil;

import org.apache.commons.lang3.StringUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class AttanceRecordBean {

    public ArrayList<CheckBean> getOverTimeCheck() {

        ArrayList<CheckBean> checkBeans1 =new ArrayList<>() ;



        if(getCheckinrecordlist()==null)
        {
            return checkBeans1;
        }

        CheckBean end = getEnd();
        if(end==null){
            return checkBeans1;
        }
        for (int i=0;i<getCheckinrecordlist().size();i++){


            if(getCheckinrecordlist().get(i).getCheckinrecordcategory().equals("2")||getCheckinrecordlist().get(i).getCheckinrecordkind().equals("2")){


                if(end.getCheckinrecordid().equals(getCheckinrecordlist().get(i).getCheckinrecordid())){

                }else {
                    checkBeans1.add(getCheckinrecordlist().get(i));
                }



            }
        }

        return checkBeans1;
    }
    public String getCheckinresult() {
        return checkinresult;
    }

    public void setCheckinresult(String checkinresult) {
        this.checkinresult = checkinresult;
    }

    /**
     * checkinattendacetimespanname : 中班
     * checkinid : 1
     * checkinaddtime : 2019-07-18 09:43:21
     * checkinno : 2019071909521001
     * checkinattendacetimespan_timelength : 11:00
     * checkinlocation : 泗泾镇德悦路519号,泗泾镇德悦路485号
     * checkintimelength : 09:10
     * checkinattendacetimespan_endtime : 18:00
     * checkinattendacetimespan_begintime : 07:00
     * checkinattendancegroupname : 白班
     * checkinuserid : 1
     * checkinstatus : 1
     * checkinrecordlist : [{"checkinrecordduetime":"07:00","checkinrecordcategory":"1","checkinaddtime":"2019-07-18 09:44:25","checkinrecordcheckinno":"2019071909521001","checkinrecordlocation":"泗泾镇德悦路519号","checkinrecordactualtime":"07:10","checkinrecordstatus":"1","checkinrecordid":"1","checkinrecordlng":"121.253700","checkinrecorduserid":"1","checkinrecordlat":"31.100924"},{"checkinrecordduetime":"18:00","checkinrecordcategory":"2","checkinaddtime":"2019-07-18 09:53:12","checkinrecordcheckinno":"2019071909521001","checkinrecordlocation":"泗泾镇德悦路519号","checkinrecordactualtime":"18:30","checkinrecordstatus":"1","checkinrecordid":"2","checkinrecordlng":"121.253700","checkinrecorduserid":"1","checkinrecordlat":"31.100924"}]
     */
    public  CheckBean getStart(){
        CheckBean checkBean = null;
        if(checkinrecordlist==null)
            return null;
        for (int i=0;i<checkinrecordlist.size();i++){

            if(checkinrecordlist.get(i).getCheckinrecordcategory().equals("1")&&checkinrecordlist.get(i).getCheckinrecordkind().equals("1")){
                checkBean = checkinrecordlist.get(i);
                break;
            }
        }

        return checkBean;

    }

    public  CheckBean getEnd(){
        CheckBean checkBean = null;
        if(checkinrecordlist==null)
            return null;
        for (int i=0;i<checkinrecordlist.size();i++){

            if(checkinrecordlist.get(i).getCheckinrecordcategory().equals("2")&&checkinrecordlist.get(i).getCheckinrecordkind().equals("1")){
                checkBean = checkinrecordlist.get(i);
                break;
            }
        }

        return checkBean;

    }
    private String checkinattendacetimespanname;
    private String checkinid;
    private String checkinaddtime;
    private String checkinno;
    private String checkinattendacetimespan_timelength;
    private String checkinlocation;
    private String checkintimelength;
    private String checkinattendacetimespan_endtime;
    private String checkinattendacetimespan_begintime;
    private String checkinattendancegroupname;
    private String checkinuserid;
    private String checkinresult;
    private List<CheckBean> checkinrecordlist;
    private ArrayList<UserBean> userinfo;

    public ArrayList<UserBean> getUserinfo() {
        return userinfo;
    }

    public void setUserinfo(ArrayList<UserBean> userinfo) {
        this.userinfo = userinfo;
    }
    public String getCheckinattendacetimespanname() {
        return checkinattendacetimespanname;
    }

    public void setCheckinattendacetimespanname(String checkinattendacetimespanname) {
        this.checkinattendacetimespanname = checkinattendacetimespanname;
    }

    public String getCheckinid() {
        return checkinid;
    }

    public void setCheckinid(String checkinid) {
        this.checkinid = checkinid;
    }

    public String getCheckinaddtime() {
       String [] value =StringUtils.split(checkinaddtime," ");

        if(value.length>0)
        return value[0];

        return  checkinaddtime;
    }

    public void setCheckinaddtime(String checkinaddtime) {
        this.checkinaddtime = checkinaddtime;
    }

    public String getCheckinno() {
        return checkinno;
    }

    public void setCheckinno(String checkinno) {
        this.checkinno = checkinno;
    }

    public String getCheckinattendacetimespan_timelength() {
        return checkinattendacetimespan_timelength;
    }

    public void setCheckinattendacetimespan_timelength(String checkinattendacetimespan_timelength) {
        this.checkinattendacetimespan_timelength = checkinattendacetimespan_timelength;
    }

    public String getCheckinlocation() {
        return checkinlocation;
    }

    public void setCheckinlocation(String checkinlocation) {
        this.checkinlocation = checkinlocation;
    }

    public String getCheckintimelength() {
        return checkintimelength;
    }

    public void setCheckintimelength(String checkintimelength) {
        this.checkintimelength = checkintimelength;
    }

    public String getCheckinattendacetimespan_endtime() {
        return checkinattendacetimespan_endtime;
    }

    public void setCheckinattendacetimespan_endtime(String checkinattendacetimespan_endtime) {
        this.checkinattendacetimespan_endtime = checkinattendacetimespan_endtime;
    }

    public String getCheckinattendacetimespan_begintime() {
        return checkinattendacetimespan_begintime;
    }

    public void setCheckinattendacetimespan_begintime(String checkinattendacetimespan_begintime) {
        this.checkinattendacetimespan_begintime = checkinattendacetimespan_begintime;
    }

    public String getCheckinattendancegroupname() {
        return checkinattendancegroupname;
    }

    public void setCheckinattendancegroupname(String checkinattendancegroupname) {
        this.checkinattendancegroupname = checkinattendancegroupname;
    }

    public String getCheckinuserid() {
        return checkinuserid;
    }

    public void setCheckinuserid(String checkinuserid) {
        this.checkinuserid = checkinuserid;
    }

    public String getCheckinstatus() {
        return checkinresult;
    }

    private  String getStringResult(String checkinstatus){
        //1.按时 2.迟到 3.早退 4.旷工 0.未知 -1.异

        if(checkinstatus.equals("0")){
            return "缺卡";
        }
        if(checkinstatus.equals("-1")){
            return "异常";
        }
        if(checkinstatus.equals("1")){
            return "按时";
        }
        if(checkinstatus.equals("2")){

            return "迟到";
        }
        if(checkinstatus.equals("3")){

            return "早退";
        }
        if(checkinstatus.equals("4")){
            return "旷工";
        }
        return "";
    }
    public String getCheckinstatusString() {

        String start = "";
        String end = "";
        if(getStart()==null)
        {
            start = "缺卡";
        }else {
            start =getStringResult(getStart().getCheckinrecordstatus());
        }
        if(getEnd()==null)
        {
            end = "缺卡";
        }else {
            end =getStringResult(getEnd().getCheckinrecordstatus());
        }



        return start+","+end;




    }

    public void setCheckinstatus(String checkinstatus) {
        this.checkinresult = checkinstatus;
    }

    public List<CheckBean> getCheckinrecordlist() {
        return checkinrecordlist;
    }

    public void setCheckinrecordlist(List<CheckBean> checkinrecordlist) {
        this.checkinrecordlist = checkinrecordlist;
    }

    public static class CheckinrecordlistBean {
        /**
         * checkinrecordduetime : 07:00
         * checkinrecordcategory : 1
         * checkinaddtime : 2019-07-18 09:44:25
         * checkinrecordcheckinno : 2019071909521001
         * checkinrecordlocation : 泗泾镇德悦路519号
         * checkinrecordactualtime : 07:10
         * checkinrecordstatus : 1
         * checkinrecordid : 1
         * checkinrecordlng : 121.253700
         * checkinrecorduserid : 1
         * checkinrecordlat : 31.100924
         */

        private String checkinrecordduetime;
        private String checkinrecordcategory;
        private String checkinaddtime;
        private String checkinrecordcheckinno;
        private String checkinrecordlocation;
        private String checkinrecordactualtime;
        private String checkinrecordstatus;
        private String checkinrecordid;
        private String checkinrecordlng;
        private String checkinrecorduserid;
        private String checkinrecordlat;

        public String getCheckinrecordduetime() {
            return checkinrecordduetime;
        }

        public void setCheckinrecordduetime(String checkinrecordduetime) {
            this.checkinrecordduetime = checkinrecordduetime;
        }

        public String getCheckinrecordcategory() {
            return checkinrecordcategory;
        }

        public void setCheckinrecordcategory(String checkinrecordcategory) {
            this.checkinrecordcategory = checkinrecordcategory;
        }

        public String getCheckinaddtime() {
            return checkinaddtime;
        }

        public void setCheckinaddtime(String checkinaddtime) {
            this.checkinaddtime = checkinaddtime;
        }

        public String getCheckinrecordcheckinno() {
            return checkinrecordcheckinno;
        }

        public void setCheckinrecordcheckinno(String checkinrecordcheckinno) {
            this.checkinrecordcheckinno = checkinrecordcheckinno;
        }

        public String getCheckinrecordlocation() {
            return checkinrecordlocation;
        }

        public void setCheckinrecordlocation(String checkinrecordlocation) {
            this.checkinrecordlocation = checkinrecordlocation;
        }

        public String getCheckinrecordactualtime() {
            return checkinrecordactualtime;
        }

        public void setCheckinrecordactualtime(String checkinrecordactualtime) {
            this.checkinrecordactualtime = checkinrecordactualtime;
        }

        public String getCheckinrecordstatus() {
            return checkinrecordstatus;
        }

        public void setCheckinrecordstatus(String checkinrecordstatus) {
            this.checkinrecordstatus = checkinrecordstatus;
        }

        public String getCheckinrecordid() {
            return checkinrecordid;
        }

        public void setCheckinrecordid(String checkinrecordid) {
            this.checkinrecordid = checkinrecordid;
        }

        public String getCheckinrecordlng() {
            return checkinrecordlng;
        }

        public void setCheckinrecordlng(String checkinrecordlng) {
            this.checkinrecordlng = checkinrecordlng;
        }

        public String getCheckinrecorduserid() {
            return checkinrecorduserid;
        }

        public void setCheckinrecorduserid(String checkinrecorduserid) {
            this.checkinrecorduserid = checkinrecorduserid;
        }

        public String getCheckinrecordlat() {
            return checkinrecordlat;
        }

        public void setCheckinrecordlat(String checkinrecordlat) {
            this.checkinrecordlat = checkinrecordlat;
        }
    }

    public String getHours(){
        ArrayList<String> arrayList =new ArrayList(Arrays.asList(StringUtils.split(checkinattendacetimespan_timelength,":")));

        if(arrayList.size()==2){
            if(arrayList.get(0).equals("0")){

                if(arrayList.get(1).equals("0")){

                    return "";
                }else
                {
                    return  arrayList.get(1)+"分钟";
                }
            }else {

                if(arrayList.get(1).equals("0")){

                    return arrayList.get(0)+"小时";
                }else
                {
                    return arrayList.get(0)+"小时"+ arrayList.get(1)+"分钟";
                }
            }
        }

        return "";
    }
}
